#region License

/*
  GShield - Game Shield
  Copyright (C) 2006-2007 WaveTech Digital Technologies, Inc.
                                http://www.wtdt.com

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#endregion License

#region Includes

using System;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
using WaveTech.GShield.Engine;
using WaveTech.GShield.Engine.Managers;
using WaveTech.GShield.Engine.Tools;
using WaveTech.GShield.Manager.Properties;

#endregion

namespace WaveTech.GShield.Manager
{
	public partial class MDIMain : Form
	{
		#region Constructor

		public MDIMain()
		{
			InitializeComponent();
		}

		#endregion Constructor

		#region ExitToolsStripMenuItem_Click

		private void ExitToolsStripMenuItem_Click(object sender, EventArgs e)
		{
			Application.Exit();
		}

		#endregion ExitToolsStripMenuItem_Click

		#region CascadeToolStripMenuItem_Click

		private void CascadeToolStripMenuItem_Click(object sender, EventArgs e)
		{
			LayoutMdi(MdiLayout.Cascade);
		}

		#endregion CascadeToolStripMenuItem_Click

		#region TileVerticalToolStripMenuItem_Click

		private void TileVerticalToolStripMenuItem_Click(object sender, EventArgs e)
		{
			LayoutMdi(MdiLayout.TileVertical);
		}

		#endregion TileVerticalToolStripMenuItem_Click

		#region TileHorizontalToolStripMenuItem_Click

		private void TileHorizontalToolStripMenuItem_Click(object sender, EventArgs e)
		{
			LayoutMdi(MdiLayout.TileHorizontal);
		}

		#endregion TileHorizontalToolStripMenuItem_Click

		#region ArrangeIconsToolStripMenuItem_Click

		private void ArrangeIconsToolStripMenuItem_Click(object sender, EventArgs e)
		{
			LayoutMdi(MdiLayout.ArrangeIcons);
		}

		#endregion ArrangeIconsToolStripMenuItem_Click

		#region CloseAllToolStripMenuItem_Click

		private void CloseAllToolStripMenuItem_Click(object sender, EventArgs e)
		{
			foreach (Form childForm in MdiChildren)
			{
				childForm.Close();
			}
		}

		#endregion CloseAllToolStripMenuItem_Click

		#region MDIMain_Load

		private void MDIMain_Load(object sender, EventArgs e)
		{
			tssVersion.Text = "Version: " + Application.ProductVersion;
			WindowManager.MdiParent = this;

			Dashboard dash = new Dashboard();
			dash.MdiParent = this;
			dash.Show();

			ServiceStatus();
			WatchdogStatus();
		}

		#endregion MDIMain_Load

		#region Service Status

		private void ServiceStatus()
		{
			if (ServiceManager.GetSentinelServiceStatus())
			{
				tsiSentinelStatus.ForeColor = Color.Green;
				tsiSentinelStatus.Text = "Online";
			}
			else
			{
				tsiSentinelStatus.ForeColor = Color.Red;
				tsiSentinelStatus.Text = "Offline";
			}
		}

		#endregion Service Status

		#region Watchdog Status

		private void WatchdogStatus()
		{
			if (ProcessHelper.Instance.DoesProcessExist("Watchdog"))
			{
				tsWatchdogStatus.ForeColor = Color.Green;
				tsWatchdogStatus.Text = "Online";
			}
			else
			{
				tsWatchdogStatus.ForeColor = Color.Red;
				tsWatchdogStatus.Text = "Offline";
			}
		}

		#endregion Watchdog Status

		#region optionsToolStripMenuItem_Click

		private void optionsToolStripMenuItem_Click(object sender, EventArgs e)
		{
			WindowManager.AddWindow(new Options(), false);
		}

		#endregion optionsToolStripMenuItem_Click

		#region aboutToolStripMenuItem_Click

		private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
		{
			AboutBox _aboutBox = new AboutBox();
			_aboutBox.Show();
		}

		#endregion aboutToolStripMenuItem_Click

		#region tsbRatingPolicy_Click

		private void tsbRatingPolicy_Click(object sender, EventArgs e)
		{
			WindowManager.AddWindow(new RatingPolicies());
		}

		#endregion tsbRatingPolicy_Click

		#region tsbUsagePolicy_Click

		private void tsbUsagePolicy_Click(object sender, EventArgs e)
		{
			WindowManager.AddWindow(new UsagePolicies());
		}

		#endregion tsbUsagePolicy_Click

		#region tsbBannedGames_Click

		private void tsbBannedGames_Click(object sender, EventArgs e)
		{
			WindowManager.AddWindow(new BannedGames());
		}

		#endregion tsbBannedGames_Click

		#region tsbGames_Click

		private void tsbGames_Click(object sender, EventArgs e)
		{
			WindowManager.AddWindow(new GamesList());
		}

		#endregion tsbGames_Click

		#region MDIMain_Paint

		private void MDIMain_Paint(object sender, PaintEventArgs e)
		{
			ServiceStatus();
			WatchdogStatus();
		}

		#endregion MDIMain_Paint

		#region ratingPoliciesToolStripMenuItem_Click

		private void ratingPoliciesToolStripMenuItem_Click(object sender, EventArgs e)
		{
			WindowManager.AddWindow(new RatingPolicies());
		}

		#endregion ratingPoliciesToolStripMenuItem_Click

		#region usagePoliciesToolStripMenuItem_Click

		private void usagePoliciesToolStripMenuItem_Click(object sender, EventArgs e)
		{
			WindowManager.AddWindow(new UsagePolicies());
		}

		#endregion usagePoliciesToolStripMenuItem_Click

		#region bannedGamesToolStripMenuItem_Click

		private void bannedGamesToolStripMenuItem_Click(object sender, EventArgs e)
		{
			WindowManager.AddWindow(new BannedGames());
		}

		#endregion bannedGamesToolStripMenuItem_Click

		#region gamesToolStripMenuItem_Click

		private void gamesToolStripMenuItem_Click(object sender, EventArgs e)
		{
			WindowManager.AddWindow(new GamesList());
		}

		#endregion gamesToolStripMenuItem_Click

		#region tsbOptions_Click

		private void tsbOptions_Click(object sender, EventArgs e)
		{
			WindowManager.AddWindow(new Options(), false);
		}

		#endregion tsbOptions_Click

		#region logsToolStripMenuItem_Click

		private void logsToolStripMenuItem_Click(object sender, EventArgs e)
		{
			WindowManager.AddWindow(new Logs(), false);
		}

		#endregion logsToolStripMenuItem_Click

		#region MDIMain_FormClosed

		private void MDIMain_FormClosed(object sender, FormClosedEventArgs e)
		{
			Application.Exit();
		}

		#endregion MDIMain_FormClosed

		#region hToolStripMenuItem_Click

		private void hToolStripMenuItem_Click(object sender, EventArgs e)
		{
			Links.LaunchUrl("http://www.wtdt.com");
		}

		#endregion hToolStripMenuItem_Click

		#region projectPageToolStripMenuItem_Click

		private void projectPageToolStripMenuItem_Click(object sender, EventArgs e)
		{
			Links.LaunchUrl("http://www.codeplex.com/gshield");
		}

		#endregion projectPageToolStripMenuItem_Click

		#region helpToolStripButton_Click

		private void helpToolStripButton_Click(object sender, EventArgs e)
		{
			Help.ShowHelp(this, Settings.Default.HelpFileName, HelpNavigator.Index);
		}

		#endregion helpToolStripButton_Click

		#region contentsToolStripMenuItem_Click

		private void contentsToolStripMenuItem_Click(object sender, EventArgs e)
		{
			Help.ShowHelp(this, Settings.Default.HelpFileName, HelpNavigator.TableOfContents);
		}

		#endregion contentsToolStripMenuItem_Click

		#region indexToolStripMenuItem_Click

		private void indexToolStripMenuItem_Click(object sender, EventArgs e)
		{
			Help.ShowHelp(this, Settings.Default.HelpFileName, HelpNavigator.Index);
		}

		#endregion indexToolStripMenuItem_Click

		#region searchToolStripMenuItem_Click

		private void searchToolStripMenuItem_Click(object sender, EventArgs e)
		{
			Help.ShowHelp(this, Settings.Default.HelpFileName, HelpNavigator.KeywordIndex);
		}

		#endregion searchToolStripMenuItem_Click

		#region ratingsPolicyViolationsToolStripMenuItem_Click

		private void ratingsPolicyViolationsToolStripMenuItem_Click(object sender, EventArgs e)
		{
		}

		#endregion ratingsPolicyViolationsToolStripMenuItem_Click

		#region usagePolicyViolationsToolStripMenuItem_Click

		private void usagePolicyViolationsToolStripMenuItem_Click(object sender, EventArgs e)
		{
		}

		#endregion usagePolicyViolationsToolStripMenuItem_Click

		#region totalPlayingTimeToolStripMenuItem_Click

		private void totalPlayingTimeToolStripMenuItem_Click(object sender, EventArgs e)
		{
		}

		#endregion totalPlayingTimeToolStripMenuItem_Click

		#region ratingsSystemActivityToolStripMenuItem_Click

		private void ratingsSystemActivityToolStripMenuItem_Click(object sender, EventArgs e)
		{
			ReportViewer report = new ReportViewer("WaveTech.GShield.Manager.Reports.RatingsSystemActivity.rdlc");
			report.Show();
		}

		#endregion ratingsSystemActivityToolStripMenuItem_Click

		#region globalSystemActivityToolStripMenuItem_Click

		private void globalSystemActivityToolStripMenuItem_Click(object sender, EventArgs e)
		{
			ReportViewer report = new ReportViewer("WaveTech.GShield.Manager.Reports.GlobalSystemActivity.rdlc");
			report.Show();
		}

		#endregion globalSystemActivityToolStripMenuItem_Click

		#region usageSystemActivityToolStripMenuItem_Click

		private void usageSystemActivityToolStripMenuItem_Click(object sender, EventArgs e)
		{
			ReportViewer report = new ReportViewer("WaveTech.GShield.Manager.Reports.UsageSystemActivity.rdlc");
			report.Show();
		}

		#endregion usageSystemActivityToolStripMenuItem_Click

		#region bannedSystemActivityToolStripMenuItem_Click

		private void bannedSystemActivityToolStripMenuItem_Click(object sender, EventArgs e)
		{
			ReportViewer report = new ReportViewer("WaveTech.GShield.Manager.Reports.BannedSystemActivity.rdlc");
			report.Show();
		}

		#endregion bannedSystemActivityToolStripMenuItem_Click

		#region securityActivityToolStripMenuItem_Click

		private void securityActivityToolStripMenuItem_Click(object sender, EventArgs e)
		{
			ReportViewer report = new ReportViewer("WaveTech.GShield.Manager.Reports.SecurityActivity.rdlc");
			report.Show();
		}

		#endregion securityActivityToolStripMenuItem_Click

		#region logsViewerToolStripMenuItem_Click

		private void logsViewerToolStripMenuItem_Click(object sender, EventArgs e)
		{
			WindowManager.AddWindow(new LogViewer(), false);
		}

		#endregion logsViewerToolStripMenuItem_Click

		#region startSentinelServiceToolStripMenuItem_Click

		private void startSentinelServiceToolStripMenuItem_Click(object sender, EventArgs e)
		{
			if (!ServiceManager.GetSentinelServiceStatus())
			{
				ServiceManager.StartSentinelService();
			}
			else
			{
				MessageBox.Show("Sentinel service is already runing.", "GShield", MessageBoxButtons.OK, MessageBoxIcon.Information);
			}
		}

		#endregion startSentinelServiceToolStripMenuItem_Click

		#region startWatchdogToolStripMenuItem_Click

		private void startWatchdogToolStripMenuItem_Click(object sender, EventArgs e)
		{
			if (!ProcessHelper.Instance.DoesProcessExist("Watchdog"))
			{
				ProcessStartInfo _watchdog = new ProcessStartInfo(Application.StartupPath + "\\Watchdog.exe");

				try
				{
					Process.Start(_watchdog);
				}
				catch
				{
				}
			}
			else
			{
				MessageBox.Show("Watchdog is already runing.", "GShield", MessageBoxButtons.OK, MessageBoxIcon.Information);
			}
		}

		#endregion startWatchdogToolStripMenuItem_Click
	}
}